package com.example.controller;

import com.example.pojo.CarPageQueryDTO;
import com.example.pojo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.pojo.Car;
import com.example.pojo.Result;
import com.example.service.CarService;

@Slf4j
@RestController
@RequestMapping

public class CarController {
    @Autowired
    private CarService carService;
    /**
     * 新增车辆
     * @param car
     * @return
     */

    @RequestMapping("/home")
    public Result add(@RequestBody Car car){
        log.info("新增车辆：{}",car);
        carService.add(car);
        return Result.success();
    }

    /**
     * 分页查询参数
     * @param
     * @return
     */
@GetMapping("/home/page")
    public Result<PageResult> pageQuery(CarPageQueryDTO carPageQueryDTO){
    PageResult pageResult = carService.pageQuery(carPageQueryDTO);
        return Result.success(pageResult);

    }
    /**
     * 删除车辆
     * @param
     * @return
     */
@DeleteMapping("/home")
    public Result<String> getCarById( Integer id) {
        log.info("删除车辆：{}",id);
        carService.getCarById(id);
        return Result.success();
    }
    /**
     * 借出车辆
     * @param
     * @return
     */
@GetMapping("/home/{id}")
    public Result lendCar(Integer id,Integer status){
        log.info("借出：{}",id,status);
       carService.lendCar(id,status);
        return Result.success();
    }

    /**
     *
     * 归还车辆
     * @param id
     * @param status
     * @return
     */


@PutMapping("/home/{id}")
    public Result revert(Integer id,Integer status){
        log.info("归还：{}",id,status);
        carService.revert(id,status);
        return Result.success();
    }

}
